package dev.ece.suit.hexmap.terrain;

import dev.ece.suit.hexmap.HexMapCell;
import dev.ece.suit.hexmap.HexMapCellIndex;
import dev.ece.suit.hexmap.HexMapCrevice;
import dev.ece.suit.hexmap.HexMapTriangle;
import dev.ece.util.tools.Direction;

@Deprecated
public abstract class AbstractTerrainFactory implements TerrainFactory {

	/**
	 * 设置相邻，按顺序
	 * @param cell
	 */
	protected void setNeighbor(HexMapCell[][] cells, HexMapCell cell) {
		int rows = cells.length;
		int cols = cells[0].length;
		//设置左上
		HexMapCellIndex index = HexMapCell.getHexMapCell(rows, cols, cell.getRow(), cell.getCol(), Direction.DIRECTION_5);
		if(index != null) {
			HexMapCell leftTop = index.getHexMapCell(cells);
			cell.getCells()[0] = leftTop;
			//右下
			leftTop.getCells()[3] = cell;
		}
		//设置左
		index = HexMapCell.getHexMapCell(rows, cols, cell.getRow(), cell.getCol(), Direction.DIRECTION_4);
		if(index != null) {
			HexMapCell left = index.getHexMapCell(cells);
			cell.getCells()[1] = left;
			//右
			left.getCells()[4] = cell;
		}
		//设置右上
		index = HexMapCell.getHexMapCell(rows, cols, cell.getRow(), cell.getCol(), Direction.DIRECTION_0);
		if(index != null) {
			HexMapCell rightTop = index.getHexMapCell(cells);
			cell.getCells()[5] = rightTop;
			//右
			rightTop.getCells()[2] = cell;
		}
	}
	
	protected void setNeighbor(HexMapCrevice crevice) {
		int director = crevice.getDirector();
		HexMapCell left = crevice.getCells()[0];
		HexMapCell right = crevice.getCells()[1];
		if(director == Direction.DIRECTION_0) {
			//右上
			left.getCrevices()[5] = crevice;
			right.getCrevices()[2] = crevice;
		} else if(director == Direction.DIRECTION_1) {
			//右
			left.getCrevices()[4] = crevice;
			right.getCrevices()[1] = crevice;
		} else if(director == Direction.DIRECTION_2) {
			//右下
			left.getCrevices()[3] = crevice;
			right.getCrevices()[0] = crevice;
		}
	}

	protected void setNeighbor(HexMapTriangle triangle) {
		int director = triangle.getDirector();
		if(director == 0) {
			//上
			triangle.getCells()[0].getTriangles()[5] = triangle;
			triangle.getCells()[1].getTriangles()[1] = triangle;
			triangle.getCells()[2].getTriangles()[3] = triangle;
		} else if(director == 1) {
			//下
			triangle.getCells()[0].getTriangles()[4] = triangle;
			triangle.getCells()[1].getTriangles()[0] = triangle;
			triangle.getCells()[2].getTriangles()[2] = triangle;
		}
		
	}
	
}
